package reese.think_in_java.java_21_thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * ***********************************************************
 *
 * @类名 : reese.think_in_java.java_21_thread.类名
 * @DESCRIPTION : 这家伙太懒啥都没写
 * @AUTHOR :  一个风情万种的男子
 * @DATE : 2016/5/28
 * ***********************************************************
 */
public class DaemonFromFactory implements Runnable {


    public void run() {
        try {
            while (true){
                TimeUnit.MILLISECONDS.sleep(100);
                System.out.println(Thread.currentThread() + " " + this);
            }
        } catch (InterruptedException e) {
            System.out.printf("interrupted");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService exec = Executors.newCachedThreadPool(new DeamonThreadFactory());
        for (int i = 0 ; i<10;i++){
            exec.execute(new DaemonFromFactory());
        }
        System.out.println("all daemons started !!!");
        TimeUnit.MILLISECONDS.sleep(500);
    }
}
